package com.dianda.controller;

import com.dianda.pojo.Classmate;
import com.dianda.pojo.Result;
import com.dianda.service.ClassmateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ClassmateController {

    @Autowired
    ClassmateService service;

    @PostMapping("/app3/classmate/list")
    public Result getClassmateList() {
        List<Classmate> list = service.getClassmateList();
        Result r = new Result();

        if (list != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setList(list);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }

    @PostMapping("/app4/classmate/findone")
    public Result getClassmateByid(@RequestBody Classmate mate){
        Integer id =mate.getId();
        Classmate m1=service.findById(id);
        Result r=new Result();
        if (m1 != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setClassmate(m1);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
}
